package com.example.administrator.waitan.mine.history;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ListView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.example.administrator.waitan.R;
import com.example.administrator.waitan.base.BaseActivity;
import com.example.administrator.waitan.tools.GsonRequest;
import com.example.administrator.waitan.tools.VolleySingleton;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by Administrator on 2016/1/23.
 */
public class HistoryActivity extends BaseActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_history);
        Log.d("bai",toEncoder("白羊座"));
        final ListView mListView = (ListView) findViewById(R.id.lv_history);
        final EditText etDay = (EditText) findViewById(R.id.et_history_day);
        final EditText etMorth = (EditText) findViewById(R.id.et_history_morth);
        findViewById(R.id.btn_history_look).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String day = etDay.getText().toString();
                String morth = etMorth.getText().toString();
                final String url ="http://v.juhe.cn/todayOnhistory/queryEvent.php?date=" + day + "%2F" + morth + "&key=533f1e09b3ef39ebf8b051f7c89af4d4";

                GsonRequest<HistoryBeans> beansGsonRequest = new GsonRequest<HistoryBeans>(url, HistoryBeans.class, new Response.Listener<HistoryBeans>() {
                    @Override
                    public void onResponse(HistoryBeans response) {
                        HistoryBaseAdapter mAdapter = new HistoryBaseAdapter(response.getResult(), HistoryActivity.this);
                        mListView.setAdapter(mAdapter);
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {

                    }
                });
                VolleySingleton.getInstance()._addRequest(beansGsonRequest);
            }
        });

    }
    //将普通字符串转换成
    //application/x-www-form-urlencoded字符串
    public static final String toEncoder(String url) {
        try {
            return URLEncoder.encode(url, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }


}
